/*
 * $Id: LatLng.java 42 2013-04-17 15:33:59Z gabakyan $
 * $Author: gabakyan $
 * $Revision: 42 $
 * $Date: 2013-04-17 15:33:59 +0000 (Wed, 17 Apr 2013) $
 *
 * Copyright (c) 2013 Supply Chain Intelligence (SCI), Inc.
 * http://www.scintelligence.com/, Email: info@scintelligence.com
 * All rights reserved.
 *
 * This file is part of Logistics Map.
 *
 * Logistics Map is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 *
 * Logistics Map is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Logistics Map.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.sci.logisticsmap.support.model.geocoding;

import com.sci.logisticsmap.support.Constants;

import java.io.Serializable;
import java.math.BigDecimal;

/**
 * The interface {@code LatLng} represents the geocoding Lat & Lng.
 *
 * @author gabakyan@gmail.com (Last modified by $Author: gabakyan $)
 * @version $Revision: 42 $
 */
public class LatLng implements Serializable {
    /**
     * The serial version id.
     */
    private static final long serialVersionUID = 1L;

    /**
     * The lat.
     */
    private BigDecimal lat;
    /**
     * The lng.
     */
    private BigDecimal lng;

    /**
     * The default constructor.
     * Constructs a new Lat & Lng.
     */
    public LatLng() {
    }

    /**
     * Constructs a new Lat & Lng.
     *
     * @param lat The lat.
     * @param lng The lng.
     */
    public LatLng(BigDecimal lat, BigDecimal lng) {
        this.lat = lat;
        this.lng = lng;
    }

    /**
     * Gets the lat.
     *
     * @return The lat.
     */
    public BigDecimal getLat() {
        return lat;
    }

    /**
     * Sets the lat.
     *
     * @param lat The lat.
     */
    public void setLat(BigDecimal lat) {
        this.lat = lat;
    }

    /**
     * Gets the lng.
     *
     * @return The lng.
     */
    public BigDecimal getLng() {
        return lng;
    }

    /**
     * Sets the lng.
     *
     * @param lng The lng.
     */
    public void setLng(BigDecimal lng) {
        this.lng = lng;
    }

    /*
     * (non-Javadoc)
     *
     * @see Object#equals(Object)
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        LatLng latLng = (LatLng) o;

        if (lat != null ? !lat.equals(latLng.lat) : latLng.lat != null) return false;
        if (lng != null ? !lng.equals(latLng.lng) : latLng.lng != null) return false;

        return true;
    }

    /*
     * (non-Javadoc)
     *
     * @see Object#hashCode()
     */
    @Override
    public int hashCode() {
        int result = lat != null ? lat.hashCode() : 0;
        result = 31 * result + (lng != null ? lng.hashCode() : 0);
        return result;
    }

    /*
     * (non-Javadoc)
     *
     * @see Object#toString()
     */
    @Override
    public String toString() {
        /*return "LatLng{" +
                "lat=" + lat +
                ", lng=" + lng +
                '}';*/
        return toString(Constants.LAT_LNG_DEFAULT_PRECISION);
    }

    /**
     * Returns a string representation of the object.
     *
     * @param precision The precision.
     * @return  a string representation of the object.
     */
    public String toString(int precision) {
        return lat.setScale(precision, BigDecimal.ROUND_HALF_EVEN).toString() + "," + lng.setScale(precision, BigDecimal.ROUND_HALF_EVEN).toString();
    }
}
